package ir;

import run.Cell;

public class InstanceRef extends CellUnit {

	public InstanceRef(String label) {
		super(label);
		setLabelName(label);
	}
	
	@Override
	public Cell getUnderlyingObject(StructuralDefinition d) {
		return d.findInstance(labelName).getUnderlyingObject(d);
	}
	
	/** 
	 * Resolve the reference (another cell instance defined earlier with in the same
	 * structural definition.
	 */
	public Cell genesis(StructuralDefinition d) {
		CellUnit instance = d.findInstance(getLabel());
		return instance.getUnderlyingObject(d);
	}
	
	public InstanceRef clone() {
		InstanceRef instanceRef = new InstanceRef(cellTypeName);
		instanceRef.setLabelName(cellTypeName);
		return instanceRef;
	}
	
}
